package com.tarena.test.stream.sender.controller;

import com.alibaba.fastjson2.JSON;
import com.tarena.test.stream.pojo.MyMessage;
import com.tarena.test.stream.sender.mq.StreamOutputChannelSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableBinding(value = {StreamOutputChannelSource.class})
public class SenderController {
    @Autowired
    private StreamOutputChannelSource streamOutputChannelSource;
    @GetMapping("/send")
    public String sendCoupon(){
        MyMessage message=new MyMessage();
        message.setAge(19);
        message.setCode("190");
        message.setName("王翠花");
        MessageChannel output = streamOutputChannelSource.output();
        System.out.println(output.getClass().getName());
        output.send(MessageBuilder.withPayload(message).build());
        return "success";
    }
}
